package com.rm.zeyou.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.rm.zeyou.constant.NumberConstants;
import com.rm.zeyou.entity.ChannelMerchantsConfig;
import com.rm.zeyou.mapper.ChannelMerchantsConfigMapper;
import com.rm.zeyou.response.ApiRestResponse;
import com.rm.zeyou.service.ChannelMerchantsConfigService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.rm.zeyou.util.check.CheckEmptyUtil;
import com.rm.zeyou.vo.response.ChannelMerchantsConfigResponseVo;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 * 渠道类目配置表 服务实现类
 * </p>
 *
 * @author YanYang
 * @since 2025-03-22 14:17:47
 */
@Service
public class ChannelMerchantsConfigServiceImpl extends ServiceImpl<ChannelMerchantsConfigMapper, ChannelMerchantsConfig> implements ChannelMerchantsConfigService {
    @Resource
    private ChannelMerchantsConfigMapper channelMerchantsConfigMapper;

    @Override
    public ApiRestResponse<List<ChannelMerchantsConfigResponseVo>> selectChannelMerchantsConfigList() {
        List<ChannelMerchantsConfigResponseVo> responseVoList = new ArrayList<>();
        List<ChannelMerchantsConfig> channelMerchantsConfigs = channelMerchantsConfigMapper.selectList(new LambdaQueryWrapper<ChannelMerchantsConfig>().eq(ChannelMerchantsConfig::getIsShelves, NumberConstants.ONE_CONSTANTS));
        if (CheckEmptyUtil.isEmpty(channelMerchantsConfigs)) {
            return ApiRestResponse.success(responseVoList);
        }
        channelMerchantsConfigs.forEach(item -> {
            ChannelMerchantsConfigResponseVo responseVo = new ChannelMerchantsConfigResponseVo();
            responseVo.setValue(item.getId());
            responseVo.setText(item.getName());
            responseVoList.add(responseVo);
        });


        return ApiRestResponse.success(responseVoList);
    }
}
